package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-11-19 23:16
 **/
public class LeetCode400 {

    public int findNthDigit(int n) {
        //数位
        int digit = 1;
        //数组左区间
        long start = 1;
        //当前区间个数
        long count = 9;
        while (n > count) {
            n -= count;
            digit += 1;
            start *= 10;
            count = 9 * digit * start;
        }
        long num = start + (n - 1) / digit;
        return Long.toString(num).charAt((n - 1) % digit) - '0';
    }

}
